package com.l024.meet.ui;

import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.OrientationHelper;
import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.StaggeredGridLayoutManager;

import com.l024.framework.adapter.CommonAdapter;
import com.l024.framework.adapter.CommonViewHolder;
import com.l024.framework.view.TouchPictureView;
import com.l024.meet.R;

import java.util.ArrayList;
import java.util.List;

public class TestActivity extends AppCompatActivity {

    private RecyclerView recyclerView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_test);
        TouchPictureView touchPictureView = this.findViewById(R.id.tp_code);
        touchPictureView.setOnViewResultListener(new TouchPictureView.OnViewResultListener() {
            @Override
            public void onResult(boolean isSuccess) {
                if (isSuccess) {
                    Toast.makeText(TestActivity.this, "验证通过", Toast.LENGTH_SHORT).show();
                } else {
                    Toast.makeText(TestActivity.this, "验证失败", Toast.LENGTH_SHORT).show();
                }
            }
        });
        initView();
    }

    private void initView() {
        recyclerView = (RecyclerView) findViewById(R.id.recycler_view);
        List<TestBean> lists = new ArrayList<>();
        for(int i=0;i<100;i++){
            TestBean testBean = new TestBean("小罗"+i,"我的描述-->"+i,(i%2));
            lists.add(testBean);
        }
        System.out.println("集合长度-->"+lists.size());
        CommonAdapter<TestBean> commonAdapter = new CommonAdapter<TestBean>(lists, new CommonAdapter.OnMoreBindDataListener<TestBean>() {
            @Override
            public int getItemType(int posistion) {
                return lists.get(posistion).getType();
            }

            @Override
            public void onBindViewHolder(TestBean model, CommonViewHolder commonViewHolder, int type, int position) {
                TextView name = commonViewHolder.getView(R.id.name);
                name.setText(model.getName());
                TextView remark = commonViewHolder.getView(R.id.remark);
                remark.setText(model.getRemarks());
            }

            @Override
            public int getLayoutId(int type) {
                return R.layout.test_layout;
            }
        });
//        mRecyclerView.setLayoutManager(new LinearLayoutManager(this));//这里用线性显示 类似于listview
//        mRecyclerView.setLayoutManager(new GridLayoutManager(this, 2));//这里用线性宫格显示 类似于gridview
//        mRecyclerView.setLayoutManager(new StaggeredGridLayoutManager(2, OrientationHelper.VERTICAL));//这里用线性宫格显示 类似于瀑布流
//        recyclerView.setLayoutManager(new LinearLayoutManager(this));
        recyclerView.setLayoutManager(new StaggeredGridLayoutManager(2, OrientationHelper.VERTICAL));//这里用线性宫格显示 类似于瀑布流

        recyclerView.setAdapter(commonAdapter);
    }

    class TestBean{
        private String name;
        private String remarks;

        public int getType() {
            return type;
        }

        public void setType(int type) {
            this.type = type;
        }

        private int type;

        public TestBean(String name, String remarks,int type) {
            this.name = name;
            this.remarks = remarks;
            this.type = type;
        }

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public String getRemarks() {
            return remarks;
        }

        public void setRemarks(String remarks) {
            this.remarks = remarks;
        }
    }
}
